1// Copyright 2021 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// Creating a client
12//
13// Usage example:
14//
15//   import "google.golang.org/api/mybusinessnotifications/v1"
16//   ...
17//   ctx := context.Background()
18//   mybusinessnotificationsService, err := mybusinessnotifications.NewService(ctx)
19//
20// In this example, Google Application Default Credentials are used for authentication.
21//
22// For information on how to create and obtain Application Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
23//
24// Other authentication options
25//
26// To use an API key for authentication (note: some APIs do not support API keys), use option.WithAPIKey:
27//
28//   mybusinessnotificationsService, err := mybusinessnotifications.NewService(ctx, option.WithAPIKey("AIza..."))
29//
30// To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow), use option.WithTokenSource:
31//
32//   config := &oauth2.Config{...}
33//   // ...
34//   token, err := config.Exchange(ctx, ...)
35//   mybusinessnotificationsService, err := mybusinessnotifications.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
36//
37// See https://godoc.org/google.golang.org/api/option/ for details on options.
38package mybusinessnotifications // import "google.golang.org/api/mybusinessnotifications/v1"
39
40import (
41	"bytes"
42	"context"
43	"encoding/json"
44	"errors"
45	"fmt"
46	"io"
47	"net/http"
48	"net/url"
49	"strconv"
50	"strings"
51
52	googleapi "google.golang.org/api/googleapi"
53	gensupport "google.golang.org/api/internal/gensupport"
54	option "google.golang.org/api/option"
55	internaloption "google.golang.org/api/option/internaloption"
56	htransport "google.golang.org/api/transport/http"
57)
58
59// Always reference these packages, just in case the auto-generated code
60// below doesn't.
61var _ = bytes.NewBuffer
62var _ = strconv.Itoa
63var _ = fmt.Sprintf
64var _ = json.NewDecoder
65var _ = io.Copy
66var _ = url.Parse
67var _ = gensupport.MarshalJSON
68var _ = googleapi.Version
69var _ = errors.New
70var _ = strings.Replace
71var _ = context.Canceled
72var _ = internaloption.WithDefaultEndpoint
73
74const apiId = "mybusinessnotifications:v1"
75const apiName = "mybusinessnotifications"
76const apiVersion = "v1"
77const basePath = "https://mybusinessnotifications.googleapis.com/"
78const mtlsBasePath = "https://mybusinessnotifications.mtls.googleapis.com/"
79
80// NewService creates a new Service.
81func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
82	opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
83	opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath))
84	client, endpoint, err := htransport.NewClient(ctx, opts...)
85	if err != nil {
86		return nil, err
87	}
88	s, err := New(client)
89	if err != nil {
90		return nil, err
91	}
92	if endpoint != "" {
93		s.BasePath = endpoint
94	}
95	return s, nil
96}
97
98// New creates a new Service. It uses the provided http.Client for requests.
99//
100// Deprecated: please use NewService instead.
101// To provide a custom HTTP client, use option.WithHTTPClient.
102// If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
103func New(client *http.Client) (*Service, error) {
104	if client == nil {
105		return nil, errors.New("client is nil")
106	}
107	s := &Service{client: client, BasePath: basePath}
108	s.Accounts = NewAccountsService(s)
109	return s, nil
110}
111
112type Service struct {
113	client    *http.Client
114	BasePath  string // API endpoint base URL
115	UserAgent string // optional additional User-Agent fragment
116
117	Accounts *AccountsService
118}
119
120func (s *Service) userAgent() string {
121	if s.UserAgent == "" {
122		return googleapi.UserAgent
123	}
124	return googleapi.UserAgent + " " + s.UserAgent
125}
126
127func NewAccountsService(s *Service) *AccountsService {
128	rs := &AccountsService{s: s}
129	return rs
130}
131
132type AccountsService struct {
133	s *Service
134}
135
136// NotificationSetting: A Google Pub/Sub topic where notifications can
137// be published when a location is updated or has a new review. There
138// will be only one notification setting resource per-account.
139type NotificationSetting struct {
140	// Name: Required. The resource name this setting is for. This is of the
141	// form `accounts/{account_id}/notificationSetting`.
142	Name string `json:"name,omitempty"`
143
144	// NotificationTypes: The types of notifications that will be sent to
145	// the Pub/Sub topic. To stop receiving notifications entirely, use
146	// NotificationSettings.UpdateNotificationSetting with an empty
147	// notification_types or set the pubsub_topic to an empty string.
148	//
149	// Possible values:
150	//   "NOTIFICATION_TYPE_UNSPECIFIED" - No notification type. Will not
151	// match any notifications.
152	//   "GOOGLE_UPDATE" - The location has Google updates for review. The
153	// location_name field on the notification will provide the resource
154	// name of the location with Google updates.
155	//   "NEW_REVIEW" - A new review has been added to the location. The
156	// review_name field on the notification will provide the resource name
157	// of the review that was added, and location_name will have the
158	// location's resource name.
159	//   "UPDATED_REVIEW" - A review on the location has been updated. The
160	// review_name field on the notification will provide the resource name
161	// of the review that was added, and location_name will have the
162	// location's resource name.
163	//   "NEW_CUSTOMER_MEDIA" - A new media item has been added to the
164	// location by a Google Maps user. The notification will provide the
165	// resource name of the new media item.
166	//   "NEW_QUESTION" - A new question is added to the location. The
167	// notification will provide the resource name of question.
168	//   "UPDATED_QUESTION" - A question of the location is updated. The
169	// notification will provide the resource name of question.
170	//   "NEW_ANSWER" - A new answer is added to the location. The
171	// notification will provide the resource name of question and answer.
172	//   "UPDATED_ANSWER" - An answer of the location is updated. The
173	// notification will provide the resource name of question and answer.
174	//   "DUPLICATE_LOCATION" - Indicates whether there is a change in
175	// location metadata's duplicate location field.
176	//   "LOSS_OF_VOICE_OF_MERCHANT" - Indicates whether the location has a
177	// loss in voice of merchant status. Call GetVoiceOfMerchantState rpc
178	// for more details
179	NotificationTypes []string `json:"notificationTypes,omitempty"`
180
181	// PubsubTopic: Optional. The Google Pub/Sub topic that will receive
182	// notifications when locations managed by this account are updated. If
183	// unset, no notifications will be posted. The account
184	// mybusiness-api-pubsub@system.gserviceaccount.com must have at least
185	// Publish permissions on the Pub/Sub topic.
186	PubsubTopic string `json:"pubsubTopic,omitempty"`
187
188	// ServerResponse contains the HTTP response code and headers from the
189	// server.
190	googleapi.ServerResponse `json:"-"`
191
192	// ForceSendFields is a list of field names (e.g. "Name") to
193	// unconditionally include in API requests. By default, fields with
194	// empty or default values are omitted from API requests. However, any
195	// non-pointer, non-interface field appearing in ForceSendFields will be
196	// sent to the server regardless of whether the field is empty or not.
197	// This may be used to include empty fields in Patch requests.
198	ForceSendFields []string `json:"-"`
199
200	// NullFields is a list of field names (e.g. "Name") to include in API
201	// requests with the JSON null value. By default, fields with empty
202	// values are omitted from API requests. However, any field with an
203	// empty value appearing in NullFields will be sent to the server as
204	// null. It is an error if a field in this list has a non-empty value.
205	// This may be used to include null fields in Patch requests.
206	NullFields []string `json:"-"`
207}
208
209func (s *NotificationSetting) MarshalJSON() ([]byte, error) {
210	type NoMethod NotificationSetting
211	raw := NoMethod(*s)
212	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
213}
214
215// method id "mybusinessnotifications.accounts.getNotificationSetting":
216
217type AccountsGetNotificationSettingCall struct {
218	s            *Service
219	name         string
220	urlParams_   gensupport.URLParams
221	ifNoneMatch_ string
222	ctx_         context.Context
223	header_      http.Header
224}
225
226// GetNotificationSetting: Returns the pubsub notification settings for
227// the account.
228//
229// - name: The resource name of the notification setting we are trying
230//   to fetch.
231func (r *AccountsService) GetNotificationSetting(name string) *AccountsGetNotificationSettingCall {
232	c := &AccountsGetNotificationSettingCall{s: r.s, urlParams_: make(gensupport.URLParams)}
233	c.name = name
234	return c
235}
236
237// Fields allows partial responses to be retrieved. See
238// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
239// for more information.
240func (c *AccountsGetNotificationSettingCall) Fields(s ...googleapi.Field) *AccountsGetNotificationSettingCall {
241	c.urlParams_.Set("fields", googleapi.CombineFields(s))
242	return c
243}
244
245// IfNoneMatch sets the optional parameter which makes the operation
246// fail if the object's ETag matches the given value. This is useful for
247// getting updates only after the object has changed since the last
248// request. Use googleapi.IsNotModified to check whether the response
249// error from Do is the result of In-None-Match.
250func (c *AccountsGetNotificationSettingCall) IfNoneMatch(entityTag string) *AccountsGetNotificationSettingCall {
251	c.ifNoneMatch_ = entityTag
252	return c
253}
254
255// Context sets the context to be used in this call's Do method. Any
256// pending HTTP request will be aborted if the provided context is
257// canceled.
258func (c *AccountsGetNotificationSettingCall) Context(ctx context.Context) *AccountsGetNotificationSettingCall {
259	c.ctx_ = ctx
260	return c
261}
262
263// Header returns an http.Header that can be modified by the caller to
264// add HTTP headers to the request.
265func (c *AccountsGetNotificationSettingCall) Header() http.Header {
266	if c.header_ == nil {
267		c.header_ = make(http.Header)
268	}
269	return c.header_
270}
271
272func (c *AccountsGetNotificationSettingCall) doRequest(alt string) (*http.Response, error) {
273	reqHeaders := make(http.Header)
274	reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/20210915")
275	for k, v := range c.header_ {
276		reqHeaders[k] = v
277	}
278	reqHeaders.Set("User-Agent", c.s.userAgent())
279	if c.ifNoneMatch_ != "" {
280		reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
281	}
282	var body io.Reader = nil
283	c.urlParams_.Set("alt", alt)
284	c.urlParams_.Set("prettyPrint", "false")
285	urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+name}")
286	urls += "?" + c.urlParams_.Encode()
287	req, err := http.NewRequest("GET", urls, body)
288	if err != nil {
289		return nil, err
290	}
291	req.Header = reqHeaders
292	googleapi.Expand(req.URL, map[string]string{
293		"name": c.name,
294	})
295	return gensupport.SendRequest(c.ctx_, c.s.client, req)
296}
297
298// Do executes the "mybusinessnotifications.accounts.getNotificationSetting" call.
299// Exactly one of *NotificationSetting or error will be non-nil. Any
300// non-2xx status code is an error. Response headers are in either
301// *NotificationSetting.ServerResponse.Header or (if a response was
302// returned at all) in error.(*googleapi.Error).Header. Use
303// googleapi.IsNotModified to check whether the returned error was
304// because http.StatusNotModified was returned.
305func (c *AccountsGetNotificationSettingCall) Do(opts ...googleapi.CallOption) (*NotificationSetting, error) {
306	gensupport.SetOptions(c.urlParams_, opts...)
307	res, err := c.doRequest("json")
308	if res != nil && res.StatusCode == http.StatusNotModified {
309		if res.Body != nil {
310			res.Body.Close()
311		}
312		return nil, &googleapi.Error{
313			Code:   res.StatusCode,
314			Header: res.Header,
315		}
316	}
317	if err != nil {
318		return nil, err
319	}
320	defer googleapi.CloseBody(res)
321	if err := googleapi.CheckResponse(res); err != nil {
322		return nil, err
323	}
324	ret := &NotificationSetting{
325		ServerResponse: googleapi.ServerResponse{
326			Header:         res.Header,
327			HTTPStatusCode: res.StatusCode,
328		},
329	}
330	target := &ret
331	if err := gensupport.DecodeResponse(target, res); err != nil {
332		return nil, err
333	}
334	return ret, nil
335	// {
336	//   "description": "Returns the pubsub notification settings for the account.",
337	//   "flatPath": "v1/accounts/{accountsId}/notificationSetting",
338	//   "httpMethod": "GET",
339	//   "id": "mybusinessnotifications.accounts.getNotificationSetting",
340	//   "parameterOrder": [
341	//     "name"
342	//   ],
343	//   "parameters": {
344	//     "name": {
345	//       "description": "Required. The resource name of the notification setting we are trying to fetch.",
346	//       "location": "path",
347	//       "pattern": "^accounts/[^/]+/notificationSetting$",
348	//       "required": true,
349	//       "type": "string"
350	//     }
351	//   },
352	//   "path": "v1/{+name}",
353	//   "response": {
354	//     "$ref": "NotificationSetting"
355	//   }
356	// }
357
358}
359
360// method id "mybusinessnotifications.accounts.updateNotificationSetting":
361
362type AccountsUpdateNotificationSettingCall struct {
363	s                   *Service
364	name                string
365	notificationsetting *NotificationSetting
366	urlParams_          gensupport.URLParams
367	ctx_                context.Context
368	header_             http.Header
369}
370
371// UpdateNotificationSetting: Sets the pubsub notification setting for
372// the account informing Google which topic to send pubsub notifications
373// for. Use the notification_types field within notification_setting to
374// manipulate the events an account wants to subscribe to. An account
375// will only have one notification setting resource, and only one pubsub
376// topic can be set. To delete the setting, update with an empty
377// notification_types
378//
379// - name: The resource name this setting is for. This is of the form
380//   `accounts/{account_id}/notificationSetting`.
381func (r *AccountsService) UpdateNotificationSetting(name string, notificationsetting *NotificationSetting) *AccountsUpdateNotificationSettingCall {
382	c := &AccountsUpdateNotificationSettingCall{s: r.s, urlParams_: make(gensupport.URLParams)}
383	c.name = name
384	c.notificationsetting = notificationsetting
385	return c
386}
387
388// UpdateMask sets the optional parameter "updateMask": Required. The
389// specific fields that should be updated. The only editable field is
390// notification_setting.
391func (c *AccountsUpdateNotificationSettingCall) UpdateMask(updateMask string) *AccountsUpdateNotificationSettingCall {
392	c.urlParams_.Set("updateMask", updateMask)
393	return c
394}
395
396// Fields allows partial responses to be retrieved. See
397// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
398// for more information.
399func (c *AccountsUpdateNotificationSettingCall) Fields(s ...googleapi.Field) *AccountsUpdateNotificationSettingCall {
400	c.urlParams_.Set("fields", googleapi.CombineFields(s))
401	return c
402}
403
404// Context sets the context to be used in this call's Do method. Any
405// pending HTTP request will be aborted if the provided context is
406// canceled.
407func (c *AccountsUpdateNotificationSettingCall) Context(ctx context.Context) *AccountsUpdateNotificationSettingCall {
408	c.ctx_ = ctx
409	return c
410}
411
412// Header returns an http.Header that can be modified by the caller to
413// add HTTP headers to the request.
414func (c *AccountsUpdateNotificationSettingCall) Header() http.Header {
415	if c.header_ == nil {
416		c.header_ = make(http.Header)
417	}
418	return c.header_
419}
420
421func (c *AccountsUpdateNotificationSettingCall) doRequest(alt string) (*http.Response, error) {
422	reqHeaders := make(http.Header)
423	reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/20210915")
424	for k, v := range c.header_ {
425		reqHeaders[k] = v
426	}
427	reqHeaders.Set("User-Agent", c.s.userAgent())
428	var body io.Reader = nil
429	body, err := googleapi.WithoutDataWrapper.JSONReader(c.notificationsetting)
430	if err != nil {
431		return nil, err
432	}
433	reqHeaders.Set("Content-Type", "application/json")
434	c.urlParams_.Set("alt", alt)
435	c.urlParams_.Set("prettyPrint", "false")
436	urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+name}")
437	urls += "?" + c.urlParams_.Encode()
438	req, err := http.NewRequest("PATCH", urls, body)
439	if err != nil {
440		return nil, err
441	}
442	req.Header = reqHeaders
443	googleapi.Expand(req.URL, map[string]string{
444		"name": c.name,
445	})
446	return gensupport.SendRequest(c.ctx_, c.s.client, req)
447}
448
449// Do executes the "mybusinessnotifications.accounts.updateNotificationSetting" call.
450// Exactly one of *NotificationSetting or error will be non-nil. Any
451// non-2xx status code is an error. Response headers are in either
452// *NotificationSetting.ServerResponse.Header or (if a response was
453// returned at all) in error.(*googleapi.Error).Header. Use
454// googleapi.IsNotModified to check whether the returned error was
455// because http.StatusNotModified was returned.
456func (c *AccountsUpdateNotificationSettingCall) Do(opts ...googleapi.CallOption) (*NotificationSetting, error) {
457	gensupport.SetOptions(c.urlParams_, opts...)
458	res, err := c.doRequest("json")
459	if res != nil && res.StatusCode == http.StatusNotModified {
460		if res.Body != nil {
461			res.Body.Close()
462		}
463		return nil, &googleapi.Error{
464			Code:   res.StatusCode,
465			Header: res.Header,
466		}
467	}
468	if err != nil {
469		return nil, err
470	}
471	defer googleapi.CloseBody(res)
472	if err := googleapi.CheckResponse(res); err != nil {
473		return nil, err
474	}
475	ret := &NotificationSetting{
476		ServerResponse: googleapi.ServerResponse{
477			Header:         res.Header,
478			HTTPStatusCode: res.StatusCode,
479		},
480	}
481	target := &ret
482	if err := gensupport.DecodeResponse(target, res); err != nil {
483		return nil, err
484	}
485	return ret, nil
486	// {
487	//   "description": "Sets the pubsub notification setting for the account informing Google which topic to send pubsub notifications for. Use the notification_types field within notification_setting to manipulate the events an account wants to subscribe to. An account will only have one notification setting resource, and only one pubsub topic can be set. To delete the setting, update with an empty notification_types",
488	//   "flatPath": "v1/accounts/{accountsId}/notificationSetting",
489	//   "httpMethod": "PATCH",
490	//   "id": "mybusinessnotifications.accounts.updateNotificationSetting",
491	//   "parameterOrder": [
492	//     "name"
493	//   ],
494	//   "parameters": {
495	//     "name": {
496	//       "description": "Required. The resource name this setting is for. This is of the form `accounts/{account_id}/notificationSetting`.",
497	//       "location": "path",
498	//       "pattern": "^accounts/[^/]+/notificationSetting$",
499	//       "required": true,
500	//       "type": "string"
501	//     },
502	//     "updateMask": {
503	//       "description": "Required. The specific fields that should be updated. The only editable field is notification_setting.",
504	//       "format": "google-fieldmask",
505	//       "location": "query",
506	//       "type": "string"
507	//     }
508	//   },
509	//   "path": "v1/{+name}",
510	//   "request": {
511	//     "$ref": "NotificationSetting"
512	//   },
513	//   "response": {
514	//     "$ref": "NotificationSetting"
515	//   }
516	// }
517
518}
519