...

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

Documentation: google.golang.org/api/mybusinessnotifications/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 mybusinessnotifications provides access to the My Business Notifications API.
     8  //
     9  // For product documentation, see: https://developers.google.com/my-business/
    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/mybusinessnotifications/v1"
    27  //	...
    28  //	ctx := context.Background()
    29  //	mybusinessnotificationsService, err := mybusinessnotifications.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  //	mybusinessnotificationsService, err := mybusinessnotifications.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  //	mybusinessnotificationsService, err := mybusinessnotifications.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    49  //
    50  // See [google.golang.org/api/option.ClientOption] for details on options.
    51  package mybusinessnotifications // import "google.golang.org/api/mybusinessnotifications/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 = "mybusinessnotifications:v1"
    90  const apiName = "mybusinessnotifications"
    91  const apiVersion = "v1"
    92  const basePath = "https://mybusinessnotifications.googleapis.com/"
    93  const basePathTemplate = "https://mybusinessnotifications.UNIVERSE_DOMAIN/"
    94  const mtlsBasePath = "https://mybusinessnotifications.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.Accounts = NewAccountsService(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  	Accounts *AccountsService
   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 NewAccountsService(s *Service) *AccountsService {
   146  	rs := &AccountsService{s: s}
   147  	return rs
   148  }
   149  
   150  type AccountsService struct {
   151  	s *Service
   152  }
   153  
   154  // NotificationSetting: A Google Pub/Sub topic where notifications can be
   155  // published when a location is updated or has a new review. There will be only
   156  // one notification setting resource per-account.
   157  type NotificationSetting struct {
   158  	// Name: Required. The resource name this setting is for. This is of the form
   159  	// `accounts/{account_id}/notificationSetting`.
   160  	Name string `json:"name,omitempty"`
   161  	// NotificationTypes: The types of notifications that will be sent to the
   162  	// Pub/Sub topic. To stop receiving notifications entirely, use
   163  	// NotificationSettings.UpdateNotificationSetting with an empty
   164  	// notification_types or set the pubsub_topic to an empty string.
   165  	//
   166  	// Possible values:
   167  	//   "NOTIFICATION_TYPE_UNSPECIFIED" - No notification type. Will not match any
   168  	// notifications.
   169  	//   "GOOGLE_UPDATE" - The location has Google updates for review. The
   170  	// location_name field on the notification will provide the resource name of
   171  	// the location with Google updates.
   172  	//   "NEW_REVIEW" - A new review has been added to the location. The
   173  	// review_name field on the notification will provide the resource name of the
   174  	// review that was added, and location_name will have the location's resource
   175  	// name.
   176  	//   "UPDATED_REVIEW" - A review on the location has been updated. The
   177  	// review_name field on the notification will provide the resource name of the
   178  	// review that was added, and location_name will have the location's resource
   179  	// name.
   180  	//   "NEW_CUSTOMER_MEDIA" - A new media item has been added to the location by
   181  	// a Google Maps user. The notification will provide the resource name of the
   182  	// new media item.
   183  	//   "NEW_QUESTION" - A new question is added to the location. The notification
   184  	// will provide the resource name of question.
   185  	//   "UPDATED_QUESTION" - A question of the location is updated. The
   186  	// notification will provide the resource name of question.
   187  	//   "NEW_ANSWER" - A new answer is added to the location. The notification
   188  	// will provide the resource name of question and answer.
   189  	//   "UPDATED_ANSWER" - An answer of the location is updated. The notification
   190  	// will provide the resource name of question and answer.
   191  	//   "DUPLICATE_LOCATION" - Indicates whether there is a change in location
   192  	// metadata's duplicate location field.
   193  	//   "LOSS_OF_VOICE_OF_MERCHANT" - Deprecated: Migrate the existing usages of
   194  	// this value to the more expanded "VOICE_OF_MERCHANT_UPDATED".
   195  	//   "VOICE_OF_MERCHANT_UPDATED" - Indicates whether the location has an update
   196  	// in Voice of Merchant (VOM) status. VOM dictates whether the location is in
   197  	// good standing and the merchant has control over the business on Google. Any
   198  	// edits made to the location will propagate to Maps after passing the review
   199  	// phase. Call GetVoiceOfMerchantState rpc for more details.
   200  	NotificationTypes []string `json:"notificationTypes,omitempty"`
   201  	// PubsubTopic: Optional. The Google Pub/Sub topic that will receive
   202  	// notifications when locations managed by this account are updated. If unset,
   203  	// no notifications will be posted. The account
   204  	// mybusiness-api-pubsub@system.gserviceaccount.com must have at least Publish
   205  	// permissions on the Pub/Sub topic.
   206  	PubsubTopic string `json:"pubsubTopic,omitempty"`
   207  
   208  	// ServerResponse contains the HTTP response code and headers from the server.
   209  	googleapi.ServerResponse `json:"-"`
   210  	// ForceSendFields is a list of field names (e.g. "Name") to unconditionally
   211  	// include in API requests. By default, fields with empty or default values are
   212  	// omitted from API requests. See
   213  	// https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
   214  	// details.
   215  	ForceSendFields []string `json:"-"`
   216  	// NullFields is a list of field names (e.g. "Name") to include in API requests
   217  	// with the JSON null value. By default, fields with empty values are omitted
   218  	// from API requests. See
   219  	// https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
   220  	NullFields []string `json:"-"`
   221  }
   222  
   223  func (s *NotificationSetting) MarshalJSON() ([]byte, error) {
   224  	type NoMethod NotificationSetting
   225  	return gensupport.MarshalJSON(NoMethod(*s), s.ForceSendFields, s.NullFields)
   226  }
   227  
   228  type AccountsGetNotificationSettingCall struct {
   229  	s            *Service
   230  	name         string
   231  	urlParams_   gensupport.URLParams
   232  	ifNoneMatch_ string
   233  	ctx_         context.Context
   234  	header_      http.Header
   235  }
   236  
   237  // GetNotificationSetting: Returns the pubsub notification settings for the
   238  // account.
   239  //
   240  //   - name: The resource name of the notification setting we are trying to
   241  //     fetch.
   242  func (r *AccountsService) GetNotificationSetting(name string) *AccountsGetNotificationSettingCall {
   243  	c := &AccountsGetNotificationSettingCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   244  	c.name = name
   245  	return c
   246  }
   247  
   248  // Fields allows partial responses to be retrieved. See
   249  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   250  // details.
   251  func (c *AccountsGetNotificationSettingCall) Fields(s ...googleapi.Field) *AccountsGetNotificationSettingCall {
   252  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   253  	return c
   254  }
   255  
   256  // IfNoneMatch sets an optional parameter which makes the operation fail if the
   257  // object's ETag matches the given value. This is useful for getting updates
   258  // only after the object has changed since the last request.
   259  func (c *AccountsGetNotificationSettingCall) IfNoneMatch(entityTag string) *AccountsGetNotificationSettingCall {
   260  	c.ifNoneMatch_ = entityTag
   261  	return c
   262  }
   263  
   264  // Context sets the context to be used in this call's Do method.
   265  func (c *AccountsGetNotificationSettingCall) Context(ctx context.Context) *AccountsGetNotificationSettingCall {
   266  	c.ctx_ = ctx
   267  	return c
   268  }
   269  
   270  // Header returns a http.Header that can be modified by the caller to add
   271  // headers to the request.
   272  func (c *AccountsGetNotificationSettingCall) Header() http.Header {
   273  	if c.header_ == nil {
   274  		c.header_ = make(http.Header)
   275  	}
   276  	return c.header_
   277  }
   278  
   279  func (c *AccountsGetNotificationSettingCall) doRequest(alt string) (*http.Response, error) {
   280  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_)
   281  	if c.ifNoneMatch_ != "" {
   282  		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
   283  	}
   284  	var body io.Reader = nil
   285  	c.urlParams_.Set("alt", alt)
   286  	c.urlParams_.Set("prettyPrint", "false")
   287  	urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+name}")
   288  	urls += "?" + c.urlParams_.Encode()
   289  	req, err := http.NewRequest("GET", urls, body)
   290  	if err != nil {
   291  		return nil, err
   292  	}
   293  	req.Header = reqHeaders
   294  	googleapi.Expand(req.URL, map[string]string{
   295  		"name": c.name,
   296  	})
   297  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   298  }
   299  
   300  // Do executes the "mybusinessnotifications.accounts.getNotificationSetting" call.
   301  // Any non-2xx status code is an error. Response headers are in either
   302  // *NotificationSetting.ServerResponse.Header or (if a response was returned at
   303  // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
   304  // check whether the returned error was because http.StatusNotModified was
   305  // returned.
   306  func (c *AccountsGetNotificationSettingCall) Do(opts ...googleapi.CallOption) (*NotificationSetting, error) {
   307  	gensupport.SetOptions(c.urlParams_, opts...)
   308  	res, err := c.doRequest("json")
   309  	if res != nil && res.StatusCode == http.StatusNotModified {
   310  		if res.Body != nil {
   311  			res.Body.Close()
   312  		}
   313  		return nil, gensupport.WrapError(&googleapi.Error{
   314  			Code:   res.StatusCode,
   315  			Header: res.Header,
   316  		})
   317  	}
   318  	if err != nil {
   319  		return nil, err
   320  	}
   321  	defer googleapi.CloseBody(res)
   322  	if err := googleapi.CheckResponse(res); err != nil {
   323  		return nil, gensupport.WrapError(err)
   324  	}
   325  	ret := &NotificationSetting{
   326  		ServerResponse: googleapi.ServerResponse{
   327  			Header:         res.Header,
   328  			HTTPStatusCode: res.StatusCode,
   329  		},
   330  	}
   331  	target := &ret
   332  	if err := gensupport.DecodeResponse(target, res); err != nil {
   333  		return nil, err
   334  	}
   335  	return ret, nil
   336  }
   337  
   338  type AccountsUpdateNotificationSettingCall struct {
   339  	s                   *Service
   340  	name                string
   341  	notificationsetting *NotificationSetting
   342  	urlParams_          gensupport.URLParams
   343  	ctx_                context.Context
   344  	header_             http.Header
   345  }
   346  
   347  // UpdateNotificationSetting: Sets the pubsub notification setting for the
   348  // account informing Google which topic to send pubsub notifications for. Use
   349  // the notification_types field within notification_setting to manipulate the
   350  // events an account wants to subscribe to. An account will only have one
   351  // notification setting resource, and only one pubsub topic can be set. To
   352  // delete the setting, update with an empty notification_types
   353  //
   354  //   - name: The resource name this setting is for. This is of the form
   355  //     `accounts/{account_id}/notificationSetting`.
   356  func (r *AccountsService) UpdateNotificationSetting(name string, notificationsetting *NotificationSetting) *AccountsUpdateNotificationSettingCall {
   357  	c := &AccountsUpdateNotificationSettingCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   358  	c.name = name
   359  	c.notificationsetting = notificationsetting
   360  	return c
   361  }
   362  
   363  // UpdateMask sets the optional parameter "updateMask": Required. The specific
   364  // fields that should be updated. The only editable field is
   365  // notification_setting.
   366  func (c *AccountsUpdateNotificationSettingCall) UpdateMask(updateMask string) *AccountsUpdateNotificationSettingCall {
   367  	c.urlParams_.Set("updateMask", updateMask)
   368  	return c
   369  }
   370  
   371  // Fields allows partial responses to be retrieved. See
   372  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
   373  // details.
   374  func (c *AccountsUpdateNotificationSettingCall) Fields(s ...googleapi.Field) *AccountsUpdateNotificationSettingCall {
   375  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   376  	return c
   377  }
   378  
   379  // Context sets the context to be used in this call's Do method.
   380  func (c *AccountsUpdateNotificationSettingCall) Context(ctx context.Context) *AccountsUpdateNotificationSettingCall {
   381  	c.ctx_ = ctx
   382  	return c
   383  }
   384  
   385  // Header returns a http.Header that can be modified by the caller to add
   386  // headers to the request.
   387  func (c *AccountsUpdateNotificationSettingCall) Header() http.Header {
   388  	if c.header_ == nil {
   389  		c.header_ = make(http.Header)
   390  	}
   391  	return c.header_
   392  }
   393  
   394  func (c *AccountsUpdateNotificationSettingCall) doRequest(alt string) (*http.Response, error) {
   395  	reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_)
   396  	var body io.Reader = nil
   397  	body, err := googleapi.WithoutDataWrapper.JSONReader(c.notificationsetting)
   398  	if err != nil {
   399  		return nil, err
   400  	}
   401  	c.urlParams_.Set("alt", alt)
   402  	c.urlParams_.Set("prettyPrint", "false")
   403  	urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+name}")
   404  	urls += "?" + c.urlParams_.Encode()
   405  	req, err := http.NewRequest("PATCH", urls, body)
   406  	if err != nil {
   407  		return nil, err
   408  	}
   409  	req.Header = reqHeaders
   410  	googleapi.Expand(req.URL, map[string]string{
   411  		"name": c.name,
   412  	})
   413  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   414  }
   415  
   416  // Do executes the "mybusinessnotifications.accounts.updateNotificationSetting" call.
   417  // Any non-2xx status code is an error. Response headers are in either
   418  // *NotificationSetting.ServerResponse.Header or (if a response was returned at
   419  // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
   420  // check whether the returned error was because http.StatusNotModified was
   421  // returned.
   422  func (c *AccountsUpdateNotificationSettingCall) Do(opts ...googleapi.CallOption) (*NotificationSetting, error) {
   423  	gensupport.SetOptions(c.urlParams_, opts...)
   424  	res, err := c.doRequest("json")
   425  	if res != nil && res.StatusCode == http.StatusNotModified {
   426  		if res.Body != nil {
   427  			res.Body.Close()
   428  		}
   429  		return nil, gensupport.WrapError(&googleapi.Error{
   430  			Code:   res.StatusCode,
   431  			Header: res.Header,
   432  		})
   433  	}
   434  	if err != nil {
   435  		return nil, err
   436  	}
   437  	defer googleapi.CloseBody(res)
   438  	if err := googleapi.CheckResponse(res); err != nil {
   439  		return nil, gensupport.WrapError(err)
   440  	}
   441  	ret := &NotificationSetting{
   442  		ServerResponse: googleapi.ServerResponse{
   443  			Header:         res.Header,
   444  			HTTPStatusCode: res.StatusCode,
   445  		},
   446  	}
   447  	target := &ret
   448  	if err := gensupport.DecodeResponse(target, res); err != nil {
   449  		return nil, err
   450  	}
   451  	return ret, nil
   452  }
   453  

View as plain text