...

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

Documentation: google.golang.org/api/libraryagent/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 libraryagent provides access to the Library Agent API.
     8  //
     9  // For product documentation, see: https://cloud.google.com/docs/quota
    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/libraryagent/v1"
    27  //	...
    28  //	ctx := context.Background()
    29  //	libraryagentService, err := libraryagent.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  //	libraryagentService, err := libraryagent.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  //	libraryagentService, err := libraryagent.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    49  //
    50  // See [google.golang.org/api/option.ClientOption] for details on options.
    51  package libraryagent // import "google.golang.org/api/libraryagent/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 = "libraryagent:v1"
    90  const apiName = "libraryagent"
    91  const apiVersion = "v1"
    92  const basePath = "https://libraryagent.googleapis.com/"
    93  const basePathTemplate = "https://libraryagent.UNIVERSE_DOMAIN/"
    94  const mtlsBasePath = "https://libraryagent.mtls.googleapis.com/"
    95  
    96  // OAuth2 scopes used by this API.
    97  const (
    98  	// See, edit, configure, and delete your Google Cloud data and see the email
    99  	// address for your Google Account.
   100  	CloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform"
   101  )
   102  
   103  // NewService creates a new Service.
   104  func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
   105  	scopesOption := internaloption.WithDefaultScopes(
   106  		"https://www.googleapis.com/auth/cloud-platform",
   107  	)
   108  	// NOTE: prepend, so we don't override user-specified scopes.
   109  	opts = append([]option.ClientOption{scopesOption}, opts...)
   110  	opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
   111  	opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate))
   112  	opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath))
   113  	opts = append(opts, internaloption.EnableNewAuthLibrary())
   114  	client, endpoint, err := htransport.NewClient(ctx, opts...)
   115  	if err != nil {
   116  		return nil, err
   117  	}
   118  	s, err := New(client)
   119  	if err != nil {
   120  		return nil, err
   121  	}
   122  	if endpoint != "" {
   123  		s.BasePath = endpoint
   124  	}
   125  	return s, nil
   126  }
   127  
   128  // New creates a new Service. It uses the provided http.Client for requests.
   129  //
   130  // Deprecated: please use NewService instead.
   131  // To provide a custom HTTP client, use option.WithHTTPClient.
   132  // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
   133  func New(client *http.Client) (*Service, error) {
   134  	if client == nil {
   135  		return nil, errors.New("client is nil")
   136  	}
   137  	s := &Service{client: client, BasePath: basePath}
   138  	s.Shelves = NewShelvesService(s)
   139  	return s, nil
   140  }
   141  
   142  type Service struct {
   143  	client    *http.Client
   144  	BasePath  string // API endpoint base URL
   145  	UserAgent string // optional additional User-Agent fragment
   146  
   147  	Shelves *ShelvesService
   148  }
   149  
   150  func (s *Service) userAgent() string {
   151  	if s.UserAgent == "" {
   152  		return googleapi.UserAgent
   153  	}
   154  	return googleapi.UserAgent + " " + s.UserAgent
   155  }
   156  
   157  func NewShelvesService(s *Service) *ShelvesService {
   158  	rs := &ShelvesService{s: s}
   159  	rs.Books = NewShelvesBooksService(s)
   160  	return rs
   161  }
   162  
   163  type ShelvesService struct {
   164  	s *Service
   165  
   166  	Books *ShelvesBooksService
   167  }
   168  
   169  func NewShelvesBooksService(s *Service) *ShelvesBooksService {
   170  	rs := &ShelvesBooksService{s: s}
   171  	return rs
   172  }
   173  
   174  type ShelvesBooksService struct {
   175  	s *Service
   176  }
   177  
   178  // GoogleExampleLibraryagentV1Book: A single book in the library.
   179  type GoogleExampleLibraryagentV1Book struct {
   180  	// Author: The name of the book author.
   181  	Author string `json:"author,omitempty"`
   182  	// Name: The resource name of the book. Book names have the form
   183  	// `shelves/{shelf_id}/books/{book_id}`. The name is ignored when creating a
   184  	// book.
   185  	Name string `json:"name,omitempty"`
   186  	// Read: Value indicating whether the book has been read.
   187  	Read bool `json:"read,omitempty"`
   188  	// Title: The title of the book.
   189  	Title string `json:"title,omitempty"`
   190  
   191  	// ServerResponse contains the HTTP response code and headers from the server.
   192  	googleapi.ServerResponse `json:"-"`
   193  	// ForceSendFields is a list of field names (e.g. "Author") to unconditionally
   194  	// include in API requests. By default, fields with empty or default values are
   195  	// omitted from API requests. See
   196  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   197  	// details.
   198  	ForceSendFields []string `json:"-"`
   199  	// NullFields is a list of field names (e.g. "Author") to include in API
   200  	// requests with the JSON null value. By default, fields with empty values are
   201  	// omitted from API requests. See
   202  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   203  	NullFields []string `json:"-"`
   204  }
   205  
   206  func (s *GoogleExampleLibraryagentV1Book) MarshalJSON() ([]byte, error) {
   207  	type NoMethod GoogleExampleLibraryagentV1Book
   208  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   209  }
   210  
   211  // GoogleExampleLibraryagentV1ListBooksResponse: Response message for
   212  // LibraryAgent.ListBooks.
   213  type GoogleExampleLibraryagentV1ListBooksResponse struct {
   214  	// Books: The list of books.
   215  	Books []*GoogleExampleLibraryagentV1Book `json:"books,omitempty"`
   216  	// NextPageToken: A token to retrieve next page of results. Pass this value in
   217  	// the ListBooksRequest.page_token field in the subsequent call to `ListBooks`
   218  	// method to retrieve the next page of results.
   219  	NextPageToken string `json:"nextPageToken,omitempty"`
   220  
   221  	// ServerResponse contains the HTTP response code and headers from the server.
   222  	googleapi.ServerResponse `json:"-"`
   223  	// ForceSendFields is a list of field names (e.g. "Books") 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. "Books") to include in API
   230  	// requests with the JSON null value. By default, fields with empty values are
   231  	// omitted 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 *GoogleExampleLibraryagentV1ListBooksResponse) MarshalJSON() ([]byte, error) {
   237  	type NoMethod GoogleExampleLibraryagentV1ListBooksResponse
   238  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   239  }
   240  
   241  // GoogleExampleLibraryagentV1ListShelvesResponse: Response message for
   242  // LibraryAgent.ListShelves.
   243  type GoogleExampleLibraryagentV1ListShelvesResponse struct {
   244  	// NextPageToken: A token to retrieve next page of results. Pass this value in
   245  	// the ListShelvesRequest.page_token field in the subsequent call to
   246  	// `ListShelves` method to retrieve the next page of results.
   247  	NextPageToken string `json:"nextPageToken,omitempty"`
   248  	// Shelves: The list of shelves.
   249  	Shelves []*GoogleExampleLibraryagentV1Shelf `json:"shelves,omitempty"`
   250  
   251  	// ServerResponse contains the HTTP response code and headers from the server.
   252  	googleapi.ServerResponse `json:"-"`
   253  	// ForceSendFields is a list of field names (e.g. "NextPageToken") to
   254  	// unconditionally include in API requests. By default, fields with empty or
   255  	// default values are omitted from API requests. See
   256  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   257  	// details.
   258  	ForceSendFields []string `json:"-"`
   259  	// NullFields is a list of field names (e.g. "NextPageToken") to include in API
   260  	// requests with the JSON null value. By default, fields with empty values are
   261  	// omitted from API requests. See
   262  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   263  	NullFields []string `json:"-"`
   264  }
   265  
   266  func (s *GoogleExampleLibraryagentV1ListShelvesResponse) MarshalJSON() ([]byte, error) {
   267  	type NoMethod GoogleExampleLibraryagentV1ListShelvesResponse
   268  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   269  }
   270  
   271  // GoogleExampleLibraryagentV1Shelf: A Shelf contains a collection of books
   272  // with a theme.
   273  type GoogleExampleLibraryagentV1Shelf struct {
   274  	// Name: Output only. The resource name of the shelf. Shelf names have the form
   275  	// `shelves/{shelf_id}`. The name is ignored when creating a shelf.
   276  	Name string `json:"name,omitempty"`
   277  	// Theme: The theme of the shelf
   278  	Theme string `json:"theme,omitempty"`
   279  
   280  	// ServerResponse contains the HTTP response code and headers from the server.
   281  	googleapi.ServerResponse `json:"-"`
   282  	// ForceSendFields is a list of field names (e.g. "Name") to unconditionally
   283  	// include in API requests. By default, fields with empty or default values are
   284  	// omitted from API requests. See
   285  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   286  	// details.
   287  	ForceSendFields []string `json:"-"`
   288  	// NullFields is a list of field names (e.g. "Name") to include in API requests
   289  	// with the JSON null value. By default, fields with empty values are omitted
   290  	// from API requests. See
   291  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   292  	NullFields []string `json:"-"`
   293  }
   294  
   295  func (s *GoogleExampleLibraryagentV1Shelf) MarshalJSON() ([]byte, error) {
   296  	type NoMethod GoogleExampleLibraryagentV1Shelf
   297  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   298  }
   299  
   300  type ShelvesGetCall struct {
   301  	s            *Service
   302  	name         string
   303  	urlParams_   gensupport.URLParams
   304  	ifNoneMatch_ string
   305  	ctx_         context.Context
   306  	header_      http.Header
   307  }
   308  
   309  // Get: Gets a shelf. Returns NOT_FOUND if the shelf does not exist.
   310  //
   311  // - name: The name of the shelf to retrieve.
   312  func (r *ShelvesService) Get(name string) *ShelvesGetCall {
   313  	c := &ShelvesGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   314  	c.name = name
   315  	return c
   316  }
   317  
   318  // Fields allows partial responses to be retrieved. See
   319  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   320  // details.
   321  func (c *ShelvesGetCall) Fields(s ...googleapi.Field) *ShelvesGetCall {
   322  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   323  	return c
   324  }
   325  
   326  // IfNoneMatch sets an optional parameter which makes the operation fail if the
   327  // object's ETag matches the given value. This is useful for getting updates
   328  // only after the object has changed since the last request.
   329  func (c *ShelvesGetCall) IfNoneMatch(entityTag string) *ShelvesGetCall {
   330  	c.ifNoneMatch_ = entityTag
   331  	return c
   332  }
   333  
   334  // Context sets the context to be used in this call's Do method.
   335  func (c *ShelvesGetCall) Context(ctx context.Context) *ShelvesGetCall {
   336  	c.ctx_ = ctx
   337  	return c
   338  }
   339  
   340  // Header returns a http.Header that can be modified by the caller to add
   341  // headers to the request.
   342  func (c *ShelvesGetCall) Header() http.Header {
   343  	if c.header_ == nil {
   344  		c.header_ = make(http.Header)
   345  	}
   346  	return c.header_
   347  }
   348  
   349  func (c *ShelvesGetCall) doRequest(alt string) (*http.Response, error) {
   350  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
   351  	if c.ifNoneMatch_ != "" {
   352  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   353  	}
   354  	var body io.Reader = nil
   355  	c.urlParams_.Set("alt", alt)
   356  	c.urlParams_.Set("prettyPrint", "false")
   357  	urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+name}")
   358  	urls += "?" + c.urlParams_.Encode()
   359  	req, err := http.NewRequest("GET", urls, body)
   360  	if err != nil {
   361  		return nil, err
   362  	}
   363  	req.Header = reqHeaders
   364  	googleapi.Expand(req.URL, map[string]string{
   365  		"name": c.name,
   366  	})
   367  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   368  }
   369  
   370  // Do executes the "libraryagent.shelves.get" call.
   371  // Any non-2xx status code is an error. Response headers are in either
   372  // *GoogleExampleLibraryagentV1Shelf.ServerResponse.Header or (if a response
   373  // was returned at all) in error.(*googleapi.Error).Header. Use
   374  // googleapi.IsNotModified to check whether the returned error was because
   375  // http.StatusNotModified was returned.
   376  func (c *ShelvesGetCall) Do(opts ...googleapi.CallOption) (*GoogleExampleLibraryagentV1Shelf, error) {
   377  	gensupport.SetOptions(c.urlParams_, opts...)
   378  	res, err := c.doRequest("json")
   379  	if res != nil && res.StatusCode == http.StatusNotModified {
   380  		if res.Body != nil {
   381  			res.Body.Close()
   382  		}
   383  		return nil, gensupport.WrapError(&googleapi.Error{
   384  			Code:   res.StatusCode,
   385  			Header: res.Header,
   386  		})
   387  	}
   388  	if err != nil {
   389  		return nil, err
   390  	}
   391  	defer googleapi.CloseBody(res)
   392  	if err := googleapi.CheckResponse(res); err != nil {
   393  		return nil, gensupport.WrapError(err)
   394  	}
   395  	ret := &GoogleExampleLibraryagentV1Shelf{
   396  		ServerResponse: googleapi.ServerResponse{
   397  			Header:         res.Header,
   398  			HTTPStatusCode: res.StatusCode,
   399  		},
   400  	}
   401  	target := &ret
   402  	if err := gensupport.DecodeResponse(target, res); err != nil {
   403  		return nil, err
   404  	}
   405  	return ret, nil
   406  }
   407  
   408  type ShelvesListCall struct {
   409  	s            *Service
   410  	urlParams_   gensupport.URLParams
   411  	ifNoneMatch_ string
   412  	ctx_         context.Context
   413  	header_      http.Header
   414  }
   415  
   416  // List: Lists shelves. The order is unspecified but deterministic. Newly
   417  // created shelves will not necessarily be added to the end of this list.
   418  func (r *ShelvesService) List() *ShelvesListCall {
   419  	c := &ShelvesListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   420  	return c
   421  }
   422  
   423  // PageSize sets the optional parameter "pageSize": Requested page size. Server
   424  // may return fewer shelves than requested. If unspecified, server will pick an
   425  // appropriate default.
   426  func (c *ShelvesListCall) PageSize(pageSize int64) *ShelvesListCall {
   427  	c.urlParams_.Set("pageSize", fmt.Sprint(pageSize))
   428  	return c
   429  }
   430  
   431  // PageToken sets the optional parameter "pageToken": A token identifying a
   432  // page of results the server should return. Typically, this is the value of
   433  // ListShelvesResponse.next_page_token returned from the previous call to
   434  // `ListShelves` method.
   435  func (c *ShelvesListCall) PageToken(pageToken string) *ShelvesListCall {
   436  	c.urlParams_.Set("pageToken", pageToken)
   437  	return c
   438  }
   439  
   440  // Fields allows partial responses to be retrieved. See
   441  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   442  // details.
   443  func (c *ShelvesListCall) Fields(s ...googleapi.Field) *ShelvesListCall {
   444  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   445  	return c
   446  }
   447  
   448  // IfNoneMatch sets an optional parameter which makes the operation fail if the
   449  // object's ETag matches the given value. This is useful for getting updates
   450  // only after the object has changed since the last request.
   451  func (c *ShelvesListCall) IfNoneMatch(entityTag string) *ShelvesListCall {
   452  	c.ifNoneMatch_ = entityTag
   453  	return c
   454  }
   455  
   456  // Context sets the context to be used in this call's Do method.
   457  func (c *ShelvesListCall) Context(ctx context.Context) *ShelvesListCall {
   458  	c.ctx_ = ctx
   459  	return c
   460  }
   461  
   462  // Header returns a http.Header that can be modified by the caller to add
   463  // headers to the request.
   464  func (c *ShelvesListCall) Header() http.Header {
   465  	if c.header_ == nil {
   466  		c.header_ = make(http.Header)
   467  	}
   468  	return c.header_
   469  }
   470  
   471  func (c *ShelvesListCall) doRequest(alt string) (*http.Response, error) {
   472  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
   473  	if c.ifNoneMatch_ != "" {
   474  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   475  	}
   476  	var body io.Reader = nil
   477  	c.urlParams_.Set("alt", alt)
   478  	c.urlParams_.Set("prettyPrint", "false")
   479  	urls := googleapi.ResolveRelative(c.s.BasePath, "v1/shelves")
   480  	urls += "?" + c.urlParams_.Encode()
   481  	req, err := http.NewRequest("GET", urls, body)
   482  	if err != nil {
   483  		return nil, err
   484  	}
   485  	req.Header = reqHeaders
   486  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   487  }
   488  
   489  // Do executes the "libraryagent.shelves.list" call.
   490  // Any non-2xx status code is an error. Response headers are in either
   491  // *GoogleExampleLibraryagentV1ListShelvesResponse.ServerResponse.Header or (if
   492  // a response was returned at all) in error.(*googleapi.Error).Header. Use
   493  // googleapi.IsNotModified to check whether the returned error was because
   494  // http.StatusNotModified was returned.
   495  func (c *ShelvesListCall) Do(opts ...googleapi.CallOption) (*GoogleExampleLibraryagentV1ListShelvesResponse, error) {
   496  	gensupport.SetOptions(c.urlParams_, opts...)
   497  	res, err := c.doRequest("json")
   498  	if res != nil && res.StatusCode == http.StatusNotModified {
   499  		if res.Body != nil {
   500  			res.Body.Close()
   501  		}
   502  		return nil, gensupport.WrapError(&googleapi.Error{
   503  			Code:   res.StatusCode,
   504  			Header: res.Header,
   505  		})
   506  	}
   507  	if err != nil {
   508  		return nil, err
   509  	}
   510  	defer googleapi.CloseBody(res)
   511  	if err := googleapi.CheckResponse(res); err != nil {
   512  		return nil, gensupport.WrapError(err)
   513  	}
   514  	ret := &GoogleExampleLibraryagentV1ListShelvesResponse{
   515  		ServerResponse: googleapi.ServerResponse{
   516  			Header:         res.Header,
   517  			HTTPStatusCode: res.StatusCode,
   518  		},
   519  	}
   520  	target := &ret
   521  	if err := gensupport.DecodeResponse(target, res); err != nil {
   522  		return nil, err
   523  	}
   524  	return ret, nil
   525  }
   526  
   527  // Pages invokes f for each page of results.
   528  // A non-nil error returned from f will halt the iteration.
   529  // The provided context supersedes any context provided to the Context method.
   530  func (c *ShelvesListCall) Pages(ctx context.Context, f func(*GoogleExampleLibraryagentV1ListShelvesResponse) error) error {
   531  	c.ctx_ = ctx
   532  	defer c.PageToken(c.urlParams_.Get("pageToken"))
   533  	for {
   534  		x, err := c.Do()
   535  		if err != nil {
   536  			return err
   537  		}
   538  		if err := f(x); err != nil {
   539  			return err
   540  		}
   541  		if x.NextPageToken == "" {
   542  			return nil
   543  		}
   544  		c.PageToken(x.NextPageToken)
   545  	}
   546  }
   547  
   548  type ShelvesBooksBorrowCall struct {
   549  	s          *Service
   550  	name       string
   551  	urlParams_ gensupport.URLParams
   552  	ctx_       context.Context
   553  	header_    http.Header
   554  }
   555  
   556  // Borrow: Borrow a book from the library. Returns the book if it is borrowed
   557  // successfully. Returns NOT_FOUND if the book does not exist in the library.
   558  // Returns quota exceeded error if the amount of books borrowed exceeds
   559  // allocation quota in any dimensions.
   560  //
   561  // - name: The name of the book to borrow.
   562  func (r *ShelvesBooksService) Borrow(name string) *ShelvesBooksBorrowCall {
   563  	c := &ShelvesBooksBorrowCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   564  	c.name = name
   565  	return c
   566  }
   567  
   568  // Fields allows partial responses to be retrieved. See
   569  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   570  // details.
   571  func (c *ShelvesBooksBorrowCall) Fields(s ...googleapi.Field) *ShelvesBooksBorrowCall {
   572  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   573  	return c
   574  }
   575  
   576  // Context sets the context to be used in this call's Do method.
   577  func (c *ShelvesBooksBorrowCall) Context(ctx context.Context) *ShelvesBooksBorrowCall {
   578  	c.ctx_ = ctx
   579  	return c
   580  }
   581  
   582  // Header returns a http.Header that can be modified by the caller to add
   583  // headers to the request.
   584  func (c *ShelvesBooksBorrowCall) Header() http.Header {
   585  	if c.header_ == nil {
   586  		c.header_ = make(http.Header)
   587  	}
   588  	return c.header_
   589  }
   590  
   591  func (c *ShelvesBooksBorrowCall) doRequest(alt string) (*http.Response, error) {
   592  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
   593  	var body io.Reader = nil
   594  	c.urlParams_.Set("alt", alt)
   595  	c.urlParams_.Set("prettyPrint", "false")
   596  	urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+name}:borrow")
   597  	urls += "?" + c.urlParams_.Encode()
   598  	req, err := http.NewRequest("POST", urls, body)
   599  	if err != nil {
   600  		return nil, err
   601  	}
   602  	req.Header = reqHeaders
   603  	googleapi.Expand(req.URL, map[string]string{
   604  		"name": c.name,
   605  	})
   606  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   607  }
   608  
   609  // Do executes the "libraryagent.shelves.books.borrow" call.
   610  // Any non-2xx status code is an error. Response headers are in either
   611  // *GoogleExampleLibraryagentV1Book.ServerResponse.Header or (if a response was
   612  // returned at all) in error.(*googleapi.Error).Header. Use
   613  // googleapi.IsNotModified to check whether the returned error was because
   614  // http.StatusNotModified was returned.
   615  func (c *ShelvesBooksBorrowCall) Do(opts ...googleapi.CallOption) (*GoogleExampleLibraryagentV1Book, error) {
   616  	gensupport.SetOptions(c.urlParams_, opts...)
   617  	res, err := c.doRequest("json")
   618  	if res != nil && res.StatusCode == http.StatusNotModified {
   619  		if res.Body != nil {
   620  			res.Body.Close()
   621  		}
   622  		return nil, gensupport.WrapError(&googleapi.Error{
   623  			Code:   res.StatusCode,
   624  			Header: res.Header,
   625  		})
   626  	}
   627  	if err != nil {
   628  		return nil, err
   629  	}
   630  	defer googleapi.CloseBody(res)
   631  	if err := googleapi.CheckResponse(res); err != nil {
   632  		return nil, gensupport.WrapError(err)
   633  	}
   634  	ret := &GoogleExampleLibraryagentV1Book{
   635  		ServerResponse: googleapi.ServerResponse{
   636  			Header:         res.Header,
   637  			HTTPStatusCode: res.StatusCode,
   638  		},
   639  	}
   640  	target := &ret
   641  	if err := gensupport.DecodeResponse(target, res); err != nil {
   642  		return nil, err
   643  	}
   644  	return ret, nil
   645  }
   646  
   647  type ShelvesBooksGetCall struct {
   648  	s            *Service
   649  	name         string
   650  	urlParams_   gensupport.URLParams
   651  	ifNoneMatch_ string
   652  	ctx_         context.Context
   653  	header_      http.Header
   654  }
   655  
   656  // Get: Gets a book. Returns NOT_FOUND if the book does not exist.
   657  //
   658  // - name: The name of the book to retrieve.
   659  func (r *ShelvesBooksService) Get(name string) *ShelvesBooksGetCall {
   660  	c := &ShelvesBooksGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   661  	c.name = name
   662  	return c
   663  }
   664  
   665  // Fields allows partial responses to be retrieved. See
   666  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   667  // details.
   668  func (c *ShelvesBooksGetCall) Fields(s ...googleapi.Field) *ShelvesBooksGetCall {
   669  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   670  	return c
   671  }
   672  
   673  // IfNoneMatch sets an optional parameter which makes the operation fail if the
   674  // object's ETag matches the given value. This is useful for getting updates
   675  // only after the object has changed since the last request.
   676  func (c *ShelvesBooksGetCall) IfNoneMatch(entityTag string) *ShelvesBooksGetCall {
   677  	c.ifNoneMatch_ = entityTag
   678  	return c
   679  }
   680  
   681  // Context sets the context to be used in this call's Do method.
   682  func (c *ShelvesBooksGetCall) Context(ctx context.Context) *ShelvesBooksGetCall {
   683  	c.ctx_ = ctx
   684  	return c
   685  }
   686  
   687  // Header returns a http.Header that can be modified by the caller to add
   688  // headers to the request.
   689  func (c *ShelvesBooksGetCall) Header() http.Header {
   690  	if c.header_ == nil {
   691  		c.header_ = make(http.Header)
   692  	}
   693  	return c.header_
   694  }
   695  
   696  func (c *ShelvesBooksGetCall) doRequest(alt string) (*http.Response, error) {
   697  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
   698  	if c.ifNoneMatch_ != "" {
   699  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   700  	}
   701  	var body io.Reader = nil
   702  	c.urlParams_.Set("alt", alt)
   703  	c.urlParams_.Set("prettyPrint", "false")
   704  	urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+name}")
   705  	urls += "?" + c.urlParams_.Encode()
   706  	req, err := http.NewRequest("GET", urls, body)
   707  	if err != nil {
   708  		return nil, err
   709  	}
   710  	req.Header = reqHeaders
   711  	googleapi.Expand(req.URL, map[string]string{
   712  		"name": c.name,
   713  	})
   714  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   715  }
   716  
   717  // Do executes the "libraryagent.shelves.books.get" call.
   718  // Any non-2xx status code is an error. Response headers are in either
   719  // *GoogleExampleLibraryagentV1Book.ServerResponse.Header or (if a response was
   720  // returned at all) in error.(*googleapi.Error).Header. Use
   721  // googleapi.IsNotModified to check whether the returned error was because
   722  // http.StatusNotModified was returned.
   723  func (c *ShelvesBooksGetCall) Do(opts ...googleapi.CallOption) (*GoogleExampleLibraryagentV1Book, error) {
   724  	gensupport.SetOptions(c.urlParams_, opts...)
   725  	res, err := c.doRequest("json")
   726  	if res != nil && res.StatusCode == http.StatusNotModified {
   727  		if res.Body != nil {
   728  			res.Body.Close()
   729  		}
   730  		return nil, gensupport.WrapError(&googleapi.Error{
   731  			Code:   res.StatusCode,
   732  			Header: res.Header,
   733  		})
   734  	}
   735  	if err != nil {
   736  		return nil, err
   737  	}
   738  	defer googleapi.CloseBody(res)
   739  	if err := googleapi.CheckResponse(res); err != nil {
   740  		return nil, gensupport.WrapError(err)
   741  	}
   742  	ret := &GoogleExampleLibraryagentV1Book{
   743  		ServerResponse: googleapi.ServerResponse{
   744  			Header:         res.Header,
   745  			HTTPStatusCode: res.StatusCode,
   746  		},
   747  	}
   748  	target := &ret
   749  	if err := gensupport.DecodeResponse(target, res); err != nil {
   750  		return nil, err
   751  	}
   752  	return ret, nil
   753  }
   754  
   755  type ShelvesBooksListCall struct {
   756  	s            *Service
   757  	parent       string
   758  	urlParams_   gensupport.URLParams
   759  	ifNoneMatch_ string
   760  	ctx_         context.Context
   761  	header_      http.Header
   762  }
   763  
   764  // List: Lists books in a shelf. The order is unspecified but deterministic.
   765  // Newly created books will not necessarily be added to the end of this list.
   766  // Returns NOT_FOUND if the shelf does not exist.
   767  //
   768  // - parent: The name of the shelf whose books we'd like to list.
   769  func (r *ShelvesBooksService) List(parent string) *ShelvesBooksListCall {
   770  	c := &ShelvesBooksListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   771  	c.parent = parent
   772  	return c
   773  }
   774  
   775  // PageSize sets the optional parameter "pageSize": Requested page size. Server
   776  // may return fewer books than requested. If unspecified, server will pick an
   777  // appropriate default.
   778  func (c *ShelvesBooksListCall) PageSize(pageSize int64) *ShelvesBooksListCall {
   779  	c.urlParams_.Set("pageSize", fmt.Sprint(pageSize))
   780  	return c
   781  }
   782  
   783  // PageToken sets the optional parameter "pageToken": A token identifying a
   784  // page of results the server should return. Typically, this is the value of
   785  // ListBooksResponse.next_page_token. returned from the previous call to
   786  // `ListBooks` method.
   787  func (c *ShelvesBooksListCall) PageToken(pageToken string) *ShelvesBooksListCall {
   788  	c.urlParams_.Set("pageToken", pageToken)
   789  	return c
   790  }
   791  
   792  // Fields allows partial responses to be retrieved. See
   793  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   794  // details.
   795  func (c *ShelvesBooksListCall) Fields(s ...googleapi.Field) *ShelvesBooksListCall {
   796  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   797  	return c
   798  }
   799  
   800  // IfNoneMatch sets an optional parameter which makes the operation fail if the
   801  // object's ETag matches the given value. This is useful for getting updates
   802  // only after the object has changed since the last request.
   803  func (c *ShelvesBooksListCall) IfNoneMatch(entityTag string) *ShelvesBooksListCall {
   804  	c.ifNoneMatch_ = entityTag
   805  	return c
   806  }
   807  
   808  // Context sets the context to be used in this call's Do method.
   809  func (c *ShelvesBooksListCall) Context(ctx context.Context) *ShelvesBooksListCall {
   810  	c.ctx_ = ctx
   811  	return c
   812  }
   813  
   814  // Header returns a http.Header that can be modified by the caller to add
   815  // headers to the request.
   816  func (c *ShelvesBooksListCall) Header() http.Header {
   817  	if c.header_ == nil {
   818  		c.header_ = make(http.Header)
   819  	}
   820  	return c.header_
   821  }
   822  
   823  func (c *ShelvesBooksListCall) doRequest(alt string) (*http.Response, error) {
   824  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
   825  	if c.ifNoneMatch_ != "" {
   826  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   827  	}
   828  	var body io.Reader = nil
   829  	c.urlParams_.Set("alt", alt)
   830  	c.urlParams_.Set("prettyPrint", "false")
   831  	urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+parent}/books")
   832  	urls += "?" + c.urlParams_.Encode()
   833  	req, err := http.NewRequest("GET", urls, body)
   834  	if err != nil {
   835  		return nil, err
   836  	}
   837  	req.Header = reqHeaders
   838  	googleapi.Expand(req.URL, map[string]string{
   839  		"parent": c.parent,
   840  	})
   841  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   842  }
   843  
   844  // Do executes the "libraryagent.shelves.books.list" call.
   845  // Any non-2xx status code is an error. Response headers are in either
   846  // *GoogleExampleLibraryagentV1ListBooksResponse.ServerResponse.Header or (if a
   847  // response was returned at all) in error.(*googleapi.Error).Header. Use
   848  // googleapi.IsNotModified to check whether the returned error was because
   849  // http.StatusNotModified was returned.
   850  func (c *ShelvesBooksListCall) Do(opts ...googleapi.CallOption) (*GoogleExampleLibraryagentV1ListBooksResponse, error) {
   851  	gensupport.SetOptions(c.urlParams_, opts...)
   852  	res, err := c.doRequest("json")
   853  	if res != nil && res.StatusCode == http.StatusNotModified {
   854  		if res.Body != nil {
   855  			res.Body.Close()
   856  		}
   857  		return nil, gensupport.WrapError(&googleapi.Error{
   858  			Code:   res.StatusCode,
   859  			Header: res.Header,
   860  		})
   861  	}
   862  	if err != nil {
   863  		return nil, err
   864  	}
   865  	defer googleapi.CloseBody(res)
   866  	if err := googleapi.CheckResponse(res); err != nil {
   867  		return nil, gensupport.WrapError(err)
   868  	}
   869  	ret := &GoogleExampleLibraryagentV1ListBooksResponse{
   870  		ServerResponse: googleapi.ServerResponse{
   871  			Header:         res.Header,
   872  			HTTPStatusCode: res.StatusCode,
   873  		},
   874  	}
   875  	target := &ret
   876  	if err := gensupport.DecodeResponse(target, res); err != nil {
   877  		return nil, err
   878  	}
   879  	return ret, nil
   880  }
   881  
   882  // Pages invokes f for each page of results.
   883  // A non-nil error returned from f will halt the iteration.
   884  // The provided context supersedes any context provided to the Context method.
   885  func (c *ShelvesBooksListCall) Pages(ctx context.Context, f func(*GoogleExampleLibraryagentV1ListBooksResponse) error) error {
   886  	c.ctx_ = ctx
   887  	defer c.PageToken(c.urlParams_.Get("pageToken"))
   888  	for {
   889  		x, err := c.Do()
   890  		if err != nil {
   891  			return err
   892  		}
   893  		if err := f(x); err != nil {
   894  			return err
   895  		}
   896  		if x.NextPageToken == "" {
   897  			return nil
   898  		}
   899  		c.PageToken(x.NextPageToken)
   900  	}
   901  }
   902  
   903  type ShelvesBooksReturnCall struct {
   904  	s          *Service
   905  	name       string
   906  	urlParams_ gensupport.URLParams
   907  	ctx_       context.Context
   908  	header_    http.Header
   909  }
   910  
   911  // Return: Return a book to the library. Returns the book if it is returned to
   912  // the library successfully. Returns error if the book does not belong to the
   913  // library or the users didn't borrow before.
   914  //
   915  // - name: The name of the book to return.
   916  func (r *ShelvesBooksService) Return(name string) *ShelvesBooksReturnCall {
   917  	c := &ShelvesBooksReturnCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   918  	c.name = name
   919  	return c
   920  }
   921  
   922  // Fields allows partial responses to be retrieved. See
   923  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   924  // details.
   925  func (c *ShelvesBooksReturnCall) Fields(s ...googleapi.Field) *ShelvesBooksReturnCall {
   926  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   927  	return c
   928  }
   929  
   930  // Context sets the context to be used in this call's Do method.
   931  func (c *ShelvesBooksReturnCall) Context(ctx context.Context) *ShelvesBooksReturnCall {
   932  	c.ctx_ = ctx
   933  	return c
   934  }
   935  
   936  // Header returns a http.Header that can be modified by the caller to add
   937  // headers to the request.
   938  func (c *ShelvesBooksReturnCall) Header() http.Header {
   939  	if c.header_ == nil {
   940  		c.header_ = make(http.Header)
   941  	}
   942  	return c.header_
   943  }
   944  
   945  func (c *ShelvesBooksReturnCall) doRequest(alt string) (*http.Response, error) {
   946  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
   947  	var body io.Reader = nil
   948  	c.urlParams_.Set("alt", alt)
   949  	c.urlParams_.Set("prettyPrint", "false")
   950  	urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+name}:return")
   951  	urls += "?" + c.urlParams_.Encode()
   952  	req, err := http.NewRequest("POST", urls, body)
   953  	if err != nil {
   954  		return nil, err
   955  	}
   956  	req.Header = reqHeaders
   957  	googleapi.Expand(req.URL, map[string]string{
   958  		"name": c.name,
   959  	})
   960  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   961  }
   962  
   963  // Do executes the "libraryagent.shelves.books.return" call.
   964  // Any non-2xx status code is an error. Response headers are in either
   965  // *GoogleExampleLibraryagentV1Book.ServerResponse.Header or (if a response was
   966  // returned at all) in error.(*googleapi.Error).Header. Use
   967  // googleapi.IsNotModified to check whether the returned error was because
   968  // http.StatusNotModified was returned.
   969  func (c *ShelvesBooksReturnCall) Do(opts ...googleapi.CallOption) (*GoogleExampleLibraryagentV1Book, error) {
   970  	gensupport.SetOptions(c.urlParams_, opts...)
   971  	res, err := c.doRequest("json")
   972  	if res != nil && res.StatusCode == http.StatusNotModified {
   973  		if res.Body != nil {
   974  			res.Body.Close()
   975  		}
   976  		return nil, gensupport.WrapError(&googleapi.Error{
   977  			Code:   res.StatusCode,
   978  			Header: res.Header,
   979  		})
   980  	}
   981  	if err != nil {
   982  		return nil, err
   983  	}
   984  	defer googleapi.CloseBody(res)
   985  	if err := googleapi.CheckResponse(res); err != nil {
   986  		return nil, gensupport.WrapError(err)
   987  	}
   988  	ret := &GoogleExampleLibraryagentV1Book{
   989  		ServerResponse: googleapi.ServerResponse{
   990  			Header:         res.Header,
   991  			HTTPStatusCode: res.StatusCode,
   992  		},
   993  	}
   994  	target := &ret
   995  	if err := gensupport.DecodeResponse(target, res); err != nil {
   996  		return nil, err
   997  	}
   998  	return ret, nil
   999  }
  1000  

View as plain text