...

Source file src/google.golang.org/api/indexing/v3/indexing-gen.go

Documentation: google.golang.org/api/indexing/v3

     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 indexing provides access to the Web Search Indexing API.
     8  //
     9  // For product documentation, see: https://developers.google.com/search/apis/indexing-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/indexing/v3"
    27  //	...
    28  //	ctx := context.Background()
    29  //	indexingService, err := indexing.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  //	indexingService, err := indexing.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  //	indexingService, err := indexing.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    49  //
    50  // See [google.golang.org/api/option.ClientOption] for details on options.
    51  package indexing // import "google.golang.org/api/indexing/v3"
    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 = "indexing:v3"
    90  const apiName = "indexing"
    91  const apiVersion = "v3"
    92  const basePath = "https://indexing.googleapis.com/"
    93  const basePathTemplate = "https://indexing.UNIVERSE_DOMAIN/"
    94  const mtlsBasePath = "https://indexing.mtls.googleapis.com/"
    95  
    96  // OAuth2 scopes used by this API.
    97  const (
    98  	// Submit data to Google for indexing
    99  	IndexingScope = "https://www.googleapis.com/auth/indexing"
   100  )
   101  
   102  // NewService creates a new Service.
   103  func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
   104  	scopesOption := internaloption.WithDefaultScopes(
   105  		"https://www.googleapis.com/auth/indexing",
   106  	)
   107  	// NOTE: prepend, so we don't override user-specified scopes.
   108  	opts = append([]option.ClientOption{scopesOption}, opts...)
   109  	opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
   110  	opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate))
   111  	opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath))
   112  	opts = append(opts, internaloption.EnableNewAuthLibrary())
   113  	client, endpoint, err := htransport.NewClient(ctx, opts...)
   114  	if err != nil {
   115  		return nil, err
   116  	}
   117  	s, err := New(client)
   118  	if err != nil {
   119  		return nil, err
   120  	}
   121  	if endpoint != "" {
   122  		s.BasePath = endpoint
   123  	}
   124  	return s, nil
   125  }
   126  
   127  // New creates a new Service. It uses the provided http.Client for requests.
   128  //
   129  // Deprecated: please use NewService instead.
   130  // To provide a custom HTTP client, use option.WithHTTPClient.
   131  // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
   132  func New(client *http.Client) (*Service, error) {
   133  	if client == nil {
   134  		return nil, errors.New("client is nil")
   135  	}
   136  	s := &Service{client: client, BasePath: basePath}
   137  	s.UrlNotifications = NewUrlNotificationsService(s)
   138  	return s, nil
   139  }
   140  
   141  type Service struct {
   142  	client    *http.Client
   143  	BasePath  string // API endpoint base URL
   144  	UserAgent string // optional additional User-Agent fragment
   145  
   146  	UrlNotifications *UrlNotificationsService
   147  }
   148  
   149  func (s *Service) userAgent() string {
   150  	if s.UserAgent == "" {
   151  		return googleapi.UserAgent
   152  	}
   153  	return googleapi.UserAgent + " " + s.UserAgent
   154  }
   155  
   156  func NewUrlNotificationsService(s *Service) *UrlNotificationsService {
   157  	rs := &UrlNotificationsService{s: s}
   158  	return rs
   159  }
   160  
   161  type UrlNotificationsService struct {
   162  	s *Service
   163  }
   164  
   165  // PublishUrlNotificationResponse: Output for PublishUrlNotification
   166  type PublishUrlNotificationResponse struct {
   167  	// UrlNotificationMetadata: Description of the notification events received for
   168  	// this URL.
   169  	UrlNotificationMetadata *UrlNotificationMetadata `json:"urlNotificationMetadata,omitempty"`
   170  
   171  	// ServerResponse contains the HTTP response code and headers from the server.
   172  	googleapi.ServerResponse `json:"-"`
   173  	// ForceSendFields is a list of field names (e.g. "UrlNotificationMetadata") to
   174  	// unconditionally include in API requests. By default, fields with empty or
   175  	// default values are omitted from API requests. See
   176  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   177  	// details.
   178  	ForceSendFields []string `json:"-"`
   179  	// NullFields is a list of field names (e.g. "UrlNotificationMetadata") to
   180  	// include in API requests with the JSON null value. By default, fields with
   181  	// empty values are omitted from API requests. See
   182  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   183  	NullFields []string `json:"-"`
   184  }
   185  
   186  func (s *PublishUrlNotificationResponse) MarshalJSON() ([]byte, error) {
   187  	type NoMethod PublishUrlNotificationResponse
   188  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   189  }
   190  
   191  // UrlNotification: `UrlNotification` is the resource used in all Indexing API
   192  // calls. It describes one event in the life cycle of a Web Document.
   193  type UrlNotification struct {
   194  	// NotifyTime: Creation timestamp for this notification. Users should _not_
   195  	// specify it, the field is ignored at the request time.
   196  	NotifyTime string `json:"notifyTime,omitempty"`
   197  	// Type: The URL life cycle event that Google is being notified about.
   198  	//
   199  	// Possible values:
   200  	//   "URL_NOTIFICATION_TYPE_UNSPECIFIED" - Unspecified.
   201  	//   "URL_UPDATED" - The given URL (Web document) has been updated.
   202  	//   "URL_DELETED" - The given URL (Web document) has been deleted.
   203  	Type string `json:"type,omitempty"`
   204  	// Url: The object of this notification. The URL must be owned by the publisher
   205  	// of this notification and, in case of `URL_UPDATED` notifications, it _must_
   206  	// be crawlable by Google.
   207  	Url string `json:"url,omitempty"`
   208  	// ForceSendFields is a list of field names (e.g. "NotifyTime") to
   209  	// unconditionally include in API requests. By default, fields with empty or
   210  	// default values are omitted from API requests. See
   211  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   212  	// details.
   213  	ForceSendFields []string `json:"-"`
   214  	// NullFields is a list of field names (e.g. "NotifyTime") to include in API
   215  	// requests with the JSON null value. By default, fields with empty values are
   216  	// omitted from API requests. See
   217  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   218  	NullFields []string `json:"-"`
   219  }
   220  
   221  func (s *UrlNotification) MarshalJSON() ([]byte, error) {
   222  	type NoMethod UrlNotification
   223  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   224  }
   225  
   226  // UrlNotificationMetadata: Summary of the most recent Indexing API
   227  // notifications successfully received, for a given URL.
   228  type UrlNotificationMetadata struct {
   229  	// LatestRemove: Latest notification received with type `URL_REMOVED`.
   230  	LatestRemove *UrlNotification `json:"latestRemove,omitempty"`
   231  	// LatestUpdate: Latest notification received with type `URL_UPDATED`.
   232  	LatestUpdate *UrlNotification `json:"latestUpdate,omitempty"`
   233  	// Url: URL to which this metadata refers.
   234  	Url string `json:"url,omitempty"`
   235  
   236  	// ServerResponse contains the HTTP response code and headers from the server.
   237  	googleapi.ServerResponse `json:"-"`
   238  	// ForceSendFields is a list of field names (e.g. "LatestRemove") to
   239  	// unconditionally include in API requests. By default, fields with empty or
   240  	// default values are omitted from API requests. See
   241  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   242  	// details.
   243  	ForceSendFields []string `json:"-"`
   244  	// NullFields is a list of field names (e.g. "LatestRemove") to include in API
   245  	// requests with the JSON null value. By default, fields with empty values are
   246  	// omitted from API requests. See
   247  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   248  	NullFields []string `json:"-"`
   249  }
   250  
   251  func (s *UrlNotificationMetadata) MarshalJSON() ([]byte, error) {
   252  	type NoMethod UrlNotificationMetadata
   253  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   254  }
   255  
   256  type UrlNotificationsGetMetadataCall struct {
   257  	s            *Service
   258  	urlParams_   gensupport.URLParams
   259  	ifNoneMatch_ string
   260  	ctx_         context.Context
   261  	header_      http.Header
   262  }
   263  
   264  // GetMetadata: Gets metadata about a Web Document. This method can _only_ be
   265  // used to query URLs that were previously seen in successful Indexing API
   266  // notifications. Includes the latest `UrlNotification` received via this API.
   267  func (r *UrlNotificationsService) GetMetadata() *UrlNotificationsGetMetadataCall {
   268  	c := &UrlNotificationsGetMetadataCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   269  	return c
   270  }
   271  
   272  // Url sets the optional parameter "url": URL that is being queried.
   273  func (c *UrlNotificationsGetMetadataCall) Url(url string) *UrlNotificationsGetMetadataCall {
   274  	c.urlParams_.Set("url", url)
   275  	return c
   276  }
   277  
   278  // Fields allows partial responses to be retrieved. See
   279  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   280  // details.
   281  func (c *UrlNotificationsGetMetadataCall) Fields(s ...googleapi.Field) *UrlNotificationsGetMetadataCall {
   282  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   283  	return c
   284  }
   285  
   286  // IfNoneMatch sets an optional parameter which makes the operation fail if the
   287  // object's ETag matches the given value. This is useful for getting updates
   288  // only after the object has changed since the last request.
   289  func (c *UrlNotificationsGetMetadataCall) IfNoneMatch(entityTag string) *UrlNotificationsGetMetadataCall {
   290  	c.ifNoneMatch_ = entityTag
   291  	return c
   292  }
   293  
   294  // Context sets the context to be used in this call's Do method.
   295  func (c *UrlNotificationsGetMetadataCall) Context(ctx context.Context) *UrlNotificationsGetMetadataCall {
   296  	c.ctx_ = ctx
   297  	return c
   298  }
   299  
   300  // Header returns a http.Header that can be modified by the caller to add
   301  // headers to the request.
   302  func (c *UrlNotificationsGetMetadataCall) Header() http.Header {
   303  	if c.header_ == nil {
   304  		c.header_ = make(http.Header)
   305  	}
   306  	return c.header_
   307  }
   308  
   309  func (c *UrlNotificationsGetMetadataCall) doRequest(alt string) (*http.Response, error) {
   310  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
   311  	if c.ifNoneMatch_ != "" {
   312  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   313  	}
   314  	var body io.Reader = nil
   315  	c.urlParams_.Set("alt", alt)
   316  	c.urlParams_.Set("prettyPrint", "false")
   317  	urls := googleapi.ResolveRelative(c.s.BasePath, "v3/urlNotifications/metadata")
   318  	urls += "?" + c.urlParams_.Encode()
   319  	req, err := http.NewRequest("GET", urls, body)
   320  	if err != nil {
   321  		return nil, err
   322  	}
   323  	req.Header = reqHeaders
   324  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   325  }
   326  
   327  // Do executes the "indexing.urlNotifications.getMetadata" call.
   328  // Any non-2xx status code is an error. Response headers are in either
   329  // *UrlNotificationMetadata.ServerResponse.Header or (if a response was
   330  // returned at all) in error.(*googleapi.Error).Header. Use
   331  // googleapi.IsNotModified to check whether the returned error was because
   332  // http.StatusNotModified was returned.
   333  func (c *UrlNotificationsGetMetadataCall) Do(opts ...googleapi.CallOption) (*UrlNotificationMetadata, error) {
   334  	gensupport.SetOptions(c.urlParams_, opts...)
   335  	res, err := c.doRequest("json")
   336  	if res != nil && res.StatusCode == http.StatusNotModified {
   337  		if res.Body != nil {
   338  			res.Body.Close()
   339  		}
   340  		return nil, gensupport.WrapError(&googleapi.Error{
   341  			Code:   res.StatusCode,
   342  			Header: res.Header,
   343  		})
   344  	}
   345  	if err != nil {
   346  		return nil, err
   347  	}
   348  	defer googleapi.CloseBody(res)
   349  	if err := googleapi.CheckResponse(res); err != nil {
   350  		return nil, gensupport.WrapError(err)
   351  	}
   352  	ret := &UrlNotificationMetadata{
   353  		ServerResponse: googleapi.ServerResponse{
   354  			Header:         res.Header,
   355  			HTTPStatusCode: res.StatusCode,
   356  		},
   357  	}
   358  	target := &ret
   359  	if err := gensupport.DecodeResponse(target, res); err != nil {
   360  		return nil, err
   361  	}
   362  	return ret, nil
   363  }
   364  
   365  type UrlNotificationsPublishCall struct {
   366  	s               *Service
   367  	urlnotification *UrlNotification
   368  	urlParams_      gensupport.URLParams
   369  	ctx_            context.Context
   370  	header_         http.Header
   371  }
   372  
   373  // Publish: Notifies that a URL has been updated or deleted.
   374  func (r *UrlNotificationsService) Publish(urlnotification *UrlNotification) *UrlNotificationsPublishCall {
   375  	c := &UrlNotificationsPublishCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   376  	c.urlnotification = urlnotification
   377  	return c
   378  }
   379  
   380  // Fields allows partial responses to be retrieved. See
   381  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   382  // details.
   383  func (c *UrlNotificationsPublishCall) Fields(s ...googleapi.Field) *UrlNotificationsPublishCall {
   384  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   385  	return c
   386  }
   387  
   388  // Context sets the context to be used in this call's Do method.
   389  func (c *UrlNotificationsPublishCall) Context(ctx context.Context) *UrlNotificationsPublishCall {
   390  	c.ctx_ = ctx
   391  	return c
   392  }
   393  
   394  // Header returns a http.Header that can be modified by the caller to add
   395  // headers to the request.
   396  func (c *UrlNotificationsPublishCall) Header() http.Header {
   397  	if c.header_ == nil {
   398  		c.header_ = make(http.Header)
   399  	}
   400  	return c.header_
   401  }
   402  
   403  func (c *UrlNotificationsPublishCall) doRequest(alt string) (*http.Response, error) {
   404  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_)
   405  	var body io.Reader = nil
   406  	body, err := googleapi.WithoutDataWrapper.JSONReader(c.urlnotification)
   407  	if err != nil {
   408  		return nil, err
   409  	}
   410  	c.urlParams_.Set("alt", alt)
   411  	c.urlParams_.Set("prettyPrint", "false")
   412  	urls := googleapi.ResolveRelative(c.s.BasePath, "v3/urlNotifications:publish")
   413  	urls += "?" + c.urlParams_.Encode()
   414  	req, err := http.NewRequest("POST", urls, body)
   415  	if err != nil {
   416  		return nil, err
   417  	}
   418  	req.Header = reqHeaders
   419  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   420  }
   421  
   422  // Do executes the "indexing.urlNotifications.publish" call.
   423  // Any non-2xx status code is an error. Response headers are in either
   424  // *PublishUrlNotificationResponse.ServerResponse.Header or (if a response was
   425  // returned at all) in error.(*googleapi.Error).Header. Use
   426  // googleapi.IsNotModified to check whether the returned error was because
   427  // http.StatusNotModified was returned.
   428  func (c *UrlNotificationsPublishCall) Do(opts ...googleapi.CallOption) (*PublishUrlNotificationResponse, error) {
   429  	gensupport.SetOptions(c.urlParams_, opts...)
   430  	res, err := c.doRequest("json")
   431  	if res != nil && res.StatusCode == http.StatusNotModified {
   432  		if res.Body != nil {
   433  			res.Body.Close()
   434  		}
   435  		return nil, gensupport.WrapError(&googleapi.Error{
   436  			Code:   res.StatusCode,
   437  			Header: res.Header,
   438  		})
   439  	}
   440  	if err != nil {
   441  		return nil, err
   442  	}
   443  	defer googleapi.CloseBody(res)
   444  	if err := googleapi.CheckResponse(res); err != nil {
   445  		return nil, gensupport.WrapError(err)
   446  	}
   447  	ret := &PublishUrlNotificationResponse{
   448  		ServerResponse: googleapi.ServerResponse{
   449  			Header:         res.Header,
   450  			HTTPStatusCode: res.StatusCode,
   451  		},
   452  	}
   453  	target := &ret
   454  	if err := gensupport.DecodeResponse(target, res); err != nil {
   455  		return nil, err
   456  	}
   457  	return ret, nil
   458  }
   459  

View as plain text